package com.ddwl.shop.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.BaseBo;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.shop.QueryShopApproveBo;
import com.ddwl.schema.bo.shop.ShopApproveBo;
import com.ddwl.schema.bo.shop.SubmitBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.shop.ShopApproveVo;
import com.ddwl.shop.service.ShopApproveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 门店审核
 *
 * @author wenbin
 * @version 1.0.0.RELEASE
 */
@Api(tags = "门店审核服务")
@RestController
@RequestMapping("/shopApprove")
public class ShopApproveController extends BaseController {

    @Resource
    private ShopApproveService shopApproveService;


    @PostMapping("/createShopApprove")
    @ApiOperation("创建门店申请")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo createShopApprove(@Validated(BaseBo.Create.class) @RequestBody ShopApproveBo bo) {
        bo.setUserId(getUserId());
        shopApproveService.createShopApprove(bo);
        return RestVo.ok();
    }

    @PostMapping("/updateShopApprove")
    @ApiOperation("修改门店申请")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo updateShopApprove(@Validated(BaseBo.Update.class) @RequestBody ShopApproveBo bo) {
        bo.setUserId(getUserId());
        shopApproveService.updateShopApprove(bo);
        return RestVo.ok();
    }

    @PostMapping("/cancelShopApprove")
    @ApiOperation("取消门店申请")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo cancelShopApprove(@RequestParam String approveId) {
        shopApproveService.cancelShopApprove(approveId, getUserId());
        return RestVo.ok();
    }

    @PostMapping("/submitShopApprove")
    @ApiOperation("提交门店申请")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<String> submitShopApprove(@Valid @RequestBody SubmitBo submitBo) {
        submitBo.setProduct(getProduct());
        String payId = shopApproveService.submitShopApprove(getUserId(), submitBo);
        return RestVo.ok(payId);
    }

    @PostMapping("/passShopApprove")
    @ApiOperation("通过门店申请")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo passShopApprove(@RequestParam String approveId,@RequestParam(required = false) @ApiParam("店铺的类型：0普通店铺，3营运车辆") Integer shopType) {
        shopApproveService.passShopApprove(approveId, getUserId(),shopType);
        return RestVo.ok();
    }

    @PostMapping("/forcePassShopApprove")
    @ApiOperation("强制通过门店申请")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo forcePassShopApprove(@RequestParam String approveId,@RequestParam(required = false) @ApiParam("店铺的类型：0普通店铺，3营运车辆") Integer shopType) {
        shopApproveService.forcePassShopApprove(approveId, getUserId(),shopType);
        return RestVo.ok();
    }

    @PostMapping("/rejectShopApprove")
    @ApiOperation("拒绝门店申请")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo rejectShopApprove(@RequestParam String approveId, @RequestParam String rejectReason) {
        shopApproveService.rejectShopApprove(approveId, rejectReason, getUserId());
        return RestVo.ok();
    }

    @DeleteMapping("/deleteShopApprove")
    @ApiOperation("删除门店申请")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo deleteShopApprove(@RequestParam String approveId) {
        shopApproveService.deleteShopApprove(approveId, getUserId());
        return RestVo.ok();
    }

    @GetMapping("/getShopApproveDetailConsole")
    @ApiOperation("获取门店申请明细 后台")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<ShopApproveVo> detailConsole(@RequestParam String id) {
        ShopApproveVo byId = shopApproveService.getByIdConsole(id);
        return RestVo.ok(byId);
    }

    @GetMapping("/getShopApproveDetail")
    @ApiOperation("获取门店申请明细 小程序")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<ShopApproveVo> detail() {
        ShopApproveVo byId = shopApproveService.getById(getUserId());
        return RestVo.ok(byId);
    }

    @PostMapping("/getShopApprovePage")
    @ApiOperation("分页查询门店申请 后台")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<PageVo<ShopApproveVo>> getShopApprovePage(@Valid @RequestBody PageBo<QueryShopApproveBo> pageBo) {
        if (null == pageBo.getParam()) {
            pageBo.setParam(new QueryShopApproveBo());
        }
        PageVo<ShopApproveVo> page = shopApproveService.page(pageBo);
        return RestVo.ok(page);
    }

    @PostMapping("/saveShopAssistFund")
    @ApiOperation("领取帮扶基金")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo saveShopAssistFund() {
        shopApproveService.saveShopAssistFund(getUserId());
        return RestVo.ok();
    }
}
